package com.zhidisoft.system.vo;

import org.apache.commons.lang3.StringUtils;

import com.zhidisoft.system.entity.Function;
import com.zhidisoft.system.entity.User;
import com.zhidisoft.util.DateUtil;

public class FunctionVO {
	
	private String id;
	
	private String funcName;
	
	private String funcCode;
	
	private String funcURL;
	
	private String funcNote;
	
	private Integer funcType;
	
	private String iconClass;
	
	private String iconURL;
	
	private String parentId;
	
	private Integer sortNum;
	
	private Integer status;
	
	private String createTime;
	
	private String createBy;
	
	private String createById;
	
	private String updateTime;
	
	private String updateBy;
	
	private String updateById;

	public String getId() {
		return id;
	}

	public String getFuncName() {
		return funcName;
	}

	public String getFuncCode() {
		return funcCode;
	}

	public String getFuncURL() {
		return funcURL;
	}
	
	public String getFuncNote() {
		return funcNote;
	}

	public void setFuncNote(String funcNote) {
		this.funcNote = funcNote;
	}
	
	public Integer getFuncType() {
		return funcType;
	}

	public void setFuncType(Integer funcType) {
		this.funcType = funcType;
	}

	public String getIconClass() {
		return iconClass;
	}

	public String getIconURL() {
		return iconURL;
	}

	public String getParentId() {
		return parentId;
	}

	public Integer getSortNum() {
		return sortNum;
	}

	public Integer getStatus() {
		return status;
	}

	public String getCreateTime() {
		return createTime;
	}

	public String getCreateBy() {
		return createBy;
	}

	public String getCreateById() {
		return createById;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public String getUpdateBy() {
		return updateBy;
	}

	public String getUpdateById() {
		return updateById;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setFuncName(String funcName) {
		this.funcName = funcName;
	}

	public void setFuncCode(String funcCode) {
		this.funcCode = funcCode;
	}

	public void setFuncURL(String funcURL) {
		this.funcURL = funcURL;
	}

	public void setIconClass(String iconClass) {
		this.iconClass = iconClass;
	}

	public void setIconURL(String iconURL) {
		this.iconURL = iconURL;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public void setSortNum(Integer sortNum) {
		this.sortNum = sortNum;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	public void setCreateById(String createById) {
		this.createById = createById;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy;
	}

	public void setUpdateById(String updateById) {
		this.updateById = updateById;
	}
	
	public static FunctionVO fromFunction(Function func){
		
		if(func!=null){
			FunctionVO vo = new FunctionVO();
			vo.setId(func.getId());
			vo.setFuncCode(func.getFuncCode());
			vo.setFuncName(func.getFuncName());
			vo.setFuncURL(func.getFuncURL());
			vo.setFuncNote(func.getFuncNote());
			vo.setFuncType(func.getFuncType());
			vo.setSortNum(func.getSortNum());
			vo.setStatus(func.getStatus());
			vo.setIconClass(func.getIconClass());
			vo.setIconURL(func.getIconURL());
			
			vo.setCreateTime(DateUtil.formatDate(func.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
			vo.setUpdateTime(DateUtil.formatDate(func.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"));
			
			if(func.getParent()!=null){
				vo.setParentId(func.getParent().getId());
			}
			
			if(func.getCreateUser()!=null){
				vo.setCreateBy(func.getCreateUser().getUsername());
				vo.setCreateById(func.getCreateUser().getId());
			}
			
			if(func.getUpdateUser()!=null){
				vo.setUpdateBy(func.getUpdateUser().getUsername());
				vo.setUpdateById(func.getUpdateUser().getId());
			}
			
			return vo;
		}
		
		return null;
	}
	
	public static Function toFunction(FunctionVO vo){
		if(vo!=null){
			Function func = new Function();
			if(StringUtils.isNotBlank(vo.getId())){
				func.setId(vo.getId());
			}
			func.setFuncCode(vo.getFuncCode());
			func.setFuncName(vo.getFuncName());
			func.setFuncURL(vo.getFuncURL());
			func.setFuncNote(vo.getFuncNote());
			func.setFuncType(vo.getFuncType());
			func.setSortNum(vo.getSortNum());
			func.setStatus(vo.getStatus());
			func.setIconClass(vo.getIconClass());
			func.setIconURL(vo.getIconURL());
			
			func.setCreateTime(DateUtil.parseDate(vo.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
			func.setUpdateTime(DateUtil.parseDate(vo.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"));
			
			if(StringUtils.isNotBlank(vo.getParentId())){
				Function parent = new Function();
				parent.setId(vo.getParentId());
				func.setParent(parent);
			}
			
			if(StringUtils.isNotBlank(vo.getCreateById())){
				User user = new User();
				user.setId(vo.getCreateById());
				func.setCreateUser(user);
			}
			
			if(StringUtils.isNotBlank(vo.getUpdateById())){
				User user = new User();
				user.setId(vo.getUpdateById());
				func.setUpdateUser(user);
			}
			
			return func;
		}
		return null;
	}
	
	

}
